import pymssql


def mssql_function(sql, sql_type):
    try:
        # 建立mssql连接
        # mssql_conn = pymssql.connect(host='127.0.0.1', user='sa', password='372169zw..', database='test', charset='UTF8')
        # mssql_conn = pymssql.connect(host='172.16.6.197', user='sa', password='eHr123', database='T9IMS',charset='UTF8')
        mssql_conn = pymssql.connect(host='ZBZX02167', user='sa', password='zqy15952833087x!', database='EHR',charset='UTF8')
        mssql_cursor = mssql_conn.cursor()
        # 查询员工id
        mssql_emp_sql = sql
        mssql_cursor.execute(mssql_emp_sql)
        if sql_type == 'select':
            mssql_data_list = mssql_cursor.fetchall()
            mssql_cursor.close()
            mssql_conn.close()
            return mssql_data_list
        elif sql_type == 'insert':
            mssql_conn.commit()
            mssql_cursor.close()
            mssql_conn.close()
            return 'success'
    except Exception as e:
        print(e)
        return e